#ifndef FIELD_H
#define FIELD_H

#include <QWidget>
#include <QWheelEvent>
#include <QMouseEvent>

#include "fileParser.h"
#include "colorBar.h"
#include "renderpseudothread.h"

class Field : public QWidget
{
    Q_OBJECT

public:
    Field(QWidget *parent = 0);
    void loadFile(QString fileName);
    void exportImage(QString fileName);
    void loadColorBar(colorBar* aColBar);
    enum viewMode {EDefault, EZoomIn, EZoomOut};

   float minHeight() {return parser->getMin(); }
   float maxHeight() {return parser->getMax(); }

public slots:
    void setZoom(int zoom);
    void grid(bool on);
    void vertexNames(bool on);
    void triangleNames(bool on);
    void contours(bool on);
    void updateImage(const QImage &);
    void defaultViewToggled();
    void zoomInToggled();
    void zoomOutToggled();

signals:
    void zoomChanged(int newZoom);
    void colorBarChanged(float aMin, float aMax);
    void enableContours(bool active);

protected:
    void paintEvent(QPaintEvent *event);
    void wheelEvent(QWheelEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void resizeEvent(QResizeEvent *event);

private:
    ~Field();
    int currentZoom;
    int zoom_x; //TODO: refactor to QPoint zoomPosition
    int zoom_y;
    int zoomChange;
    fileParser *parser;
    bool gridOn;
    bool showVertexNames;
    bool showTriangleNames;
    bool showContours;
    QPoint dragStartPosition;
    QPoint dragVector;
    viewMode curViewMode;

    RenderPseudoThread* pThread;
    QImage renderedImage;
    colorBar *colBar;

    void doPaint(QPainter& painter, bool exporting=false);

public:
   fileParser::Mode mode() {return parser->mode();}
};

#endif // FIELD_H
